package com.qf.domain;

import java.util.List;

public class PageBean<T> {
    private Integer currentPage;//当前页码
    private Integer pageSize;//显示固定的条数
    private List<T> list; //当页显示的数据
    private Integer totalCount;//总条数

    private Integer pageCount;//总页数

    private Integer startPage;//开始页数
    private Integer endPage;//结束页面

    public PageBean() {
    }

    public PageBean(Integer currentPage, Integer pageSize, List<T> list, Integer totalCount) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.list = list;
        this.totalCount = totalCount;
        //计算总页数
        this.pageCount = (totalCount % pageSize == 0) ? (totalCount / pageSize) : (totalCount / pageSize) + 1;
//添加

        //下面的判断后加代码
        //计算动态页码，正常情况下
        startPage = currentPage - 5;
        endPage = currentPage + 4;
        //查看的页面数<5
        if (this.currentPage <= 5) {
            this.startPage = 1;
            this.endPage = 10;
        }
        //查看页面大于等于pageCount-5
        if (this.currentPage >= this.pageCount - 5) {
            this.startPage = pageCount - 9;
            this.endPage = pageCount;
        }
        //页码不足十页
        if (this.pageCount <= 10) {
            this.startPage=1;
            this.endPage = pageCount;
        }
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    public Integer getPageCount() {
        return pageCount;
    }

    public void setPageCount(Integer pageCount) {
        this.pageCount = pageCount;
    }

    public Integer getStartPage() {
        return startPage;
    }

    public void setStartPage(Integer startPage) {
        this.startPage = startPage;
    }

    public Integer getEndPage() {
        return endPage;
    }

    public void setEndPage(Integer endPage) {
        this.endPage = endPage;
    }

    @Override
    public String toString() {
        return "PageBean{" +
                "currentPage=" + currentPage +
                ", pageSize=" + pageSize +
                ", list=" + list +
                ", totalCount=" + totalCount +
                ", pageCount=" + pageCount +
                ", startPage=" + startPage +
                ", endPage=" + endPage +
                '}';
    }
}
